// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false;

/*加载基础css*/
import './../../assets/css/base.less'; 


/*工具*/
import Utils from './../../script/utils';
Vue.use(Utils);

/*验证*/
import Validate from './../../script/validate';
Vue.use(Validate);

/*过滤器*/
import Filter from './../../script/filter';
Vue.use(Filter);

/*组件*/
import Components from './../../components';
Vue.use(Components);

/*VueResource*/
import VueResource from 'vue-resource';
Vue.use(VueResource);

/*请求*/
import Action from './../../script/action';
Vue.use(Action, {
	request(req, next, error) {
		let v = Vue.prototype;
		v.$loading = req.loading;
		Vue.http(Object.assign({
			[req.method == 'GET' ? 'params' : 'body']: Object.assign({}, req.data)
		}, req)).then(({ body, status }) => {
			v.$loading = false;
			if (status == 200) {
				if (body.status) {
					next(body.data);
				} else {
					error(() => body.message && v.$toast(body.message));
				}
			} else {
				v.$toast({
					'0': '网络断开链接',
				}[status] || '未知错误');
			}
		});
	},
	origin: 'https://www.easy-mock.com/mock/5a38b205e859572ed68551b5/api',
	method: 'GET',
	actions: {
		test: {
			url: '/test',
			loading: true
		}
	}
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>'
})
